//定义全局路径
var lujing = getPath() + '/user';

//手机号码框失去焦点，遍历数据库，检查号码是否已经注册
$('input[name="registerName"]').blur(function() {
	var registerName = $('input[name="registerName"]').val();
	$.ajax({
		type: 'post',
		url: lujing,
		async: true,
		dataType: 'json',
		data: {
			"method": "validatePhone",
			"registerName": registerName
		},
		success: function(jsonDate) {
			var num = jsonDate.counter;
			//console.log(num);
			if(num != 0) {
				$('#span3').append($('<span style="color:red;">该号码已注册</span>'));
			} else {
				$('#span3').append($('<span style="color:green;">该号码已可用</span>'));
			}
		},
	});
})
//获得焦点是，清空提示
$('input[name="registerName"]').focus(function() {
	$('#span3').empty();
})

//失去焦点时，检查密码是否一致
$('input[name="registerPassword2"]').blur(function() {
	var registerPassword1 = $('input[name="registerPassword1"]').val();
	var registerPassword2 = $('input[name="registerPassword2"]').val();
	if(registerPassword1 != registerPassword2) {
		$('#span1').append($('<span style="color:red;">两次密码不一致</span>'));
	}
})
//获得焦点是，清空提示
$('input[name="registerPassword2"]').focus(function() {
	$('#span1').empty();
})

//点击注册按钮，提交数据
$('#rg').click(function() {
	//console.log('++');
	var registerName = $('input[name="registerName"]').val();
	var registerPassword1 = $('input[name="registerPassword1"]').val();
	//var registerPassword2=$('input[name="registerPassword2"]').val();
	var registerMail = $('input[name="registerMail"]').val();
	$.ajax({
		type: 'post',
		url: lujing,
		async: true,
		dataType: 'json',
		data: {
			"method": "register",
			"registerName": registerName,
			"registerPassword1": registerPassword1,
			"registerMail": registerMail
		},
		success: function(jsonDate) {
			//console.log(jsonDate);
			var num = jsonDate.counter;
			if(num != 0) {
				window.location.href = 'home.html';
			}
		}
	});
})

//登录
$('#lg').click(function() {
	//console.log('+++');
	var loginName = $('input[name="loginName"]').val();
	var loginPassword = $('input[name="loginPassword"]').val();

	$.ajax({
		type: 'post',
		url: lujing,
		async: true,
		dataType: 'json',
		data: {
			"method": "login",
			"loginName": loginName,
			"loginPassword": loginPassword,
		},
		success: function(jsonDate) {
			//console.log(jsonDate);

			var num = jsonDate.counter;
			if(num != 0) {
				/*//在屏幕中间弹窗
				showAll('#model');*/
				window.location.href = 'home.html';
			}
		}
	});
})

